<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script src="{{ getAssets }}js/jquery.table2excel.min.js?v={{ assets_version }}"></script>
<script>
var  allocation_id = '{{.m.Id}}';
var dataTables1 = $('#dataTables').DataTable({
    order:[]
    ,columns: [
       {"bSortable": false, render:function(data, type, full, meta) {
                return productGroupName(full.Products);
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Snd.sph;
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Snd.cyl;
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Snd.add;
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Snd.model;
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Snd.color;
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Acceptance.lot_number;
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Acceptance.manufacture_date > 0 ? timetransDate(full.Acceptance.manufacture_date) : '';
            }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Acceptance.expiry_date > 0 ? timetransDate(full.Acceptance.expiry_date) : '';
            }}
        ,{"data" : "purchase_num","bSortable": false, render:function(data, type, full, meta) {
                return full.purchase_num
            }}
        ,{"data" : "purchase_num","bSortable": false, render:function(data, type, full, meta) {
                return full.allocation_num
            }}
    ]
    ,"serverSide": false
    ,"bPaginate" : false
    ,"bFilter" : false	//是否启动过滤、搜索功能
    ,"bInfo" : false //是否显示页脚信息，DataTables插件左下角显示记录数
    ,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
    ,"drawCallback": function(settings){
    }
});
var isLoading = false;
$.post('', function (res) {
    var dt = $('#dataTables').DataTable();
    $.each(res.data, function(index, value){
        var goods = [];
        value.Inventory.Products = value.Products;
        value.Inventory.Snd = value.Snd;
        value.Inventory.allocation_num = value.AllocationNum;
        dt.row.add(value.Inventory).draw();
    });
    isLoading = true;
}, 'json');

$('#download').bind("click", function(){
    if(isLoading) {
        $("#dataTables").table2excel({
            exclude: ".noExl",
            name: "导出调拨明细",
            filename: "调拨明细",
            fileext: ".xls",
            exclude_img: false,
            exclude_links: false,
            exclude_inputs: false
        });
    } else {
        layer.msg("还没加载结束请耐心等待一下！");return false;
    }
    return false;
});

//退回
$('#returnReceiveBtn').click(function () {
    layer.confirm('确认要退回该单据吗？', function (index) {
        layer.close(index);
        $.post('{{ urlfor "AllocationController.WarehousingReturnAllocation" }}', {'allocation_id':allocation_id}, function (res) {
            if(res.code == 1) {
                layer.alert(res.msg);return false;
            }
            location = '{{ urlfor "AllocationController.Warehousing" }}';
        }, 'json');
    });
});

//确认接收
$('#confirmReceiveBtn').click(function () {
    layer.confirm('确认接收该调拨单据吗？', function (index) {
        layer.close(index);
        $.post('{{ urlfor "AllocationController.WarehousingConfirmAllocation" }}', {'allocation_id':allocation_id}, function (res) {
            if(res.code == 1) {
                layer.alert(res.msg);return false;
            }
            layer.alert('接收完成', function () {
                location.reload();
            });
        }, 'json');
    });
});

</script>